<script lang="ts">
import { defineComponent, onMounted, onUnmounted } from "vue";
import { useMessage } from "naive-ui";
import type { MessageApi } from "naive-ui";

// 类型声明扩展
declare global {
  interface Window {
    $message?: MessageApi;
  }
}

export default defineComponent({
  name: "MessageContent",
  setup() {
    const message = useMessage();

    // 组件挂载时注册全局变量
    onMounted(() => {
      if (import.meta.env.PROD) {
        console.warn("[DEPRECATION] Avoid using window.$message in production - prefer dependency injection");
      }
      window.$message = message;
    });

    // 组件卸载时清理
    onUnmounted(() => {
      delete window.$message;
    });

    return () => null; // 无渲染组件
  }
});
</script>
